define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'parent/index' + location.search,
                    add_url: 'parent/add',
                    edit_url: 'parent/edit',
                    del_url: 'parent/del',
                    multi_url: 'parent/multi',
                    import_url: 'parent/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'mine_id', title: __('Mine_id')},
                        {field: 'cost', title: __('Cost'), operate:'BETWEEN'},
                        {field: 'num', title: __('Num')},
                        {field: 'total', title: __('Total'), operate:'BETWEEN'},
                        {field: 'list_order', title: __('List_order')},
                        {field: 'status', title: __('Status')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'mine.id', title: __('Mine.id')},
                        {field: 'mine.name', title: __('Mine.name'), operate: 'LIKE'},
                        {field: 'mine.avatar', title: __('Mine.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'mine.price', title: __('Mine.price'), operate:'BETWEEN'},
                        {field: 'mine.cost', title: __('Mine.cost'), operate:'BETWEEN'},
                        {field: 'mine.list_order', title: __('Mine.list_order')},
                        {field: 'mine.status', title: __('Mine.status')},
                        {field: 'mine.createtime', title: __('Mine.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'mine.updatetime', title: __('Mine.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'shop.id', title: __('Shop.id')},
                        {field: 'shop.title', title: __('Shop.title'), operate: 'LIKE'},
                        {field: 'shop.image', title: __('Shop.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'shop.price', title: __('Shop.price'), operate:'BETWEEN'},
                        {field: 'shop.category', title: __('Shop.category'), operate: 'LIKE'},
                        {field: 'shop.list_order', title: __('Shop.list_order')},
                        {field: 'shop.status', title: __('Shop.status')},
                        {field: 'shop.createtime', title: __('Shop.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'shop.updatetime', title: __('Shop.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
